// pages/integralDetail/integralDetail.js
const app = getApp();
import api from "../../../utils/util.js"
Page({
  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: app.globalData.statusBarHeight,
    fullHeight: app.globalData.fullcontain,
    discount: app.globalData.discount,
    navmess: {
      navtitle: "积分兑换",
      backhide: 0,
      topheight: 1,
    },
    swiperSetting:{
      indicatorDots: true,
      vertical: false,
      autoplay: false,
      interval: 2000,
      duration: 500,
    },
    currentObj: {
      type: 5
    },
    currentBuyNum: 1,
    demolist:[]
  },
  toDetail: function(e){
    var url = e.currentTarget.dataset.url;
    var mess = {
      activityNo: this.data.demolist.activityNo,
      quantity: this.data.currentBuyNum
    }
    wx.navigateTo({
      url: url +"?mess="+ JSON.stringify(mess) +"&type="+ this.data.currentObj.type,
    })
  },
  
  bindMinus:function(){
    if(this.data.currentBuyNum > 1){
      this.setData({
        currentBuyNum: this.data.currentBuyNum - 1
      })
    }else{
      wx.showToast({
        title: '至少选择一件商品',
        icon: "none",
        duration: 1500
      })
    }
  },
  bindPlus:function(){
    if(this.data.currentBuyNum < this.data.demolist.frequency){
      this.setData({
        currentBuyNum: this.data.currentBuyNum + 1
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this,
    check = app.checkLogin();
    if(check){
      var token = wx.getStorageSync('token');
      this.setData({
        isLogin: check,
        token: token
      })
    }
    console.log("activityNo:",options.mess);
    //积分信息
    api.post("/mini/ext/score/info",{
      "activityNo": options.mess,
      "token": token
    }).then(res => {
      console.log("积分信息",res)
      that.setData({
        demolist: res.result,
        activityNo: res.result.activityNo,
        imageUrl: res.result.imageUrl.split(",")
      })
    }).catch(res=>{
      console.log(res)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})